﻿Imports System.Object
Imports VSModel
Imports Cls_Common
Partial Class Control_VBPQ_Detail
    Inherits System.Web.UI.UserControl
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        'If Not IsPostBack Then
        '    If Not Request.QueryString("Id") Is Nothing Then
        '        hidID.Value = Request.QueryString("Id")
        '        ShowData()
        '    End If
        'End If
        Using Data As New VSEntities
            If Not IsPostBack Then
                If Not Request.QueryString("Id") Is Nothing Then
                    hidID.Value = Request.QueryString("Id")
                    'Dim cd = (From a In Data.VBPQChucDanh Join b In Data.VBPQChucDanhNguoiKy _
                    '    On a.Id Equals b.ChucDanhId Join c In Data.VBPQNguoiKy On b.NguoiKyId Equals c.Id _
                    '    Where b.DocumentId = hidID.Value Select a.ChucDanh, c.NguoiKy).ToList
                    Dim nk = (From a In Data.VBPQNguoiKies Join b In Data.VBPQChucDanhNguoiKies _
                               On a.Id Equals b.NguoiKyId Where b.DocumentId = hidID.Value Select a).Distinct().ToList
                    If Not nk Is Nothing Then
                        rptOfficeSigner.DataSource = nk
                        rptOfficeSigner.DataBind()
                    End If
                    ShowData()
                End If
            End If
        End Using
    End Sub
    Protected Sub ShowData()
        Using data As New VSEntities
            'Dim p = (From q In data.VBPQDocument Join a In data.VBPQChucDanhNguoiKy On q.Id Equals a.DocumentId _
            'Where q.Id = hidID.Value Select q).SingleOrDefault
            'Dim Id = hidID.Value
            'Dim p As IList(Of uspVBPQDetail_Result) = data.uspVBPQDetail(Id).ToList
            'If Not p Is Nothing Then
            '    For i As Integer = 0 To p.Count - 1
            '        hplTitle.Text = IIf(IsNothing(p(i).TrichYeu) = True, "", p(i).TrichYeu)
            '        ltrContent.Text = IIf(IsNothing(p(i).NoiDung) = True, "", p(i).NoiDung)
            '        lblAuthor.Text = IIf(IsNothing(p(i).ChucDanh) = True, "", p(i).ChucDanh)
            '        ltrDes.Text = IIf(IsNothing(p(i).NguoiKy) = True, "", p(i).NguoiKy)
            '    Next
            'End If
            Dim Id = hidID.Value
            Dim p As IList(Of uspVBPQDetail_Result) = data.uspVBPQDetail(Id).ToList
            If Not p Is Nothing Then
                For i As Integer = 0 To p.Count - 1
                    ltrTopType.Text = IIf(IsNothing(p(i).LoaiVanBan) = True, "", p(i).LoaiVanBan)
                    ltrTitle.Text = IIf(IsNothing(p(i).TrichYeu) = True, "", p(i).TrichYeu)
                    ltrContent.Text = IIf(IsNothing(p(i).NoiDung) = True, "", p(i).NoiDung)
                    ltrCode.Text = IIf(IsNothing(p(i).SoKyHieu) = True, "", p(i).SoKyHieu)
                    ltrTopCode.Text = IIf(IsNothing(p(i).SoKyHieu) = True, "", p(i).SoKyHieu)
                    ltrType.Text = IIf(IsNothing(p(i).LoaiVanBan) = True, "", p(i).LoaiVanBan)
                    ltrCenterTitle.Text = IIf(IsNothing(p(i).TrichYeu) = True, "", p(i).TrichYeu)
                    ltrPublishDate.Text = IIf(IsNothing(p(i).NgayBanHanh) = True, "", p(i).NgayBanHanh)
                    ltrCQBH.Text = IIf(IsNothing(p(i).CoQuanBH) = True, "", p(i).CoQuanBH)
                    ltrTopCQBH.Text = IIf(IsNothing(p(i).CoQuanBH) = True, "", p(i).CoQuanBH)
                Next
            End If
        End Using
    End Sub

    Protected Sub rptOfficeSigner_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles rptOfficeSigner.ItemDataBound
        Dim p = CType(e.Item.DataItem, Object)
        Dim nk = p.Id.ToString
        If e.Item.ItemIndex >= 0 Then
            Dim ltrSigner As Literal = CType(e.Item.FindControl("ltrSigner"), Literal)
            ltrSigner.Text = p.NguoiKy.ToString
            Using dta As New VSEntities
                Dim cd = (From a In dta.VBPQChucDanhs Join b In dta.VBPQChucDanhNguoiKies _
                              On a.Id Equals b.ChucDanhId Where b.DocumentId = hidID.Value _
                              And b.NguoiKyId = nk Select a).Distinct().ToList
                Dim rptOffice As Repeater = CType(e.Item.FindControl("rptOffice"), Repeater)
                If Not cd Is Nothing Then
                    rptOffice.DataSource = cd
                    rptOffice.DataBind()
                End If
            End Using
        End If
    End Sub
    Protected Sub rptOffice_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs)
        Dim p = CType(e.Item.DataItem, Object)
        If e.Item.ItemIndex >= 0 Then
            Dim ltrOffice As Literal = CType(e.Item.FindControl("ltrOffice"), Literal)
            ltrOffice.Text = p.ChucDanh.ToString
        End If
    End Sub
End Class
